<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['adv']=pdo_getall('jy_jd_adv',array('uniacid'=>$_SESSION['uniacid']),'','','display asc');
	//公告列表
	$pindex = max(1, intval($_RQ['page']));
	$total='';
	$notice_list = pdo_getslice('jy_jd_notice',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array($pindex,20),$total,array('id','title','createtime'),'','id desc');
	if($notice_list){
		foreach($notice_list as &$notice){
			if($_SESSION['os']=='windows'){
				$notice['createtime']=date('m-d',$notice['createtime']);
			}else{
				$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
			}
		}
	}
	$return['notice_list']=$notice_list;
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	$settime=$this->session('settime');
	$return['params']=array(
		'order'=>'all',
	);
	$return['post']=array(
		'day'=>$settime['day']?:1,
		'intime'=>$settime['intime']?:date("Y-m-d"),
		'endtime'=>$settime['endtime']?:date("Y-m-d",strtotime("+1 day")),
	);
	$return['post']['settime']=array(
			'tstart'=>strtotime($return['post']['intime']),
			'tend'=>strtotime($return['post']['endtime']),
	);
	$sharelink='jy_jd/index//fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
		'title'=>$return['pluginset']['share_title']?:'首页-在线酒店',
		'desc'=>$return['pluginset']['share_desc']?:'在线酒店，一个属于旅行之家！',
		'link'=>custom_url($sharelink,true),
		'imgUrl'=>tomedia($return['pluginset']['share_image'])
	);
	set_html('title',$return['pluginset']['title']?:'首页');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if(!empty($_RQ['keyword'])  && $_RQ['keyword']!='juli'){
		$params['title like']='%'.trim($_RQ['params']['keyword']).'%';
		$return['params']['title']=$_RQ['keyword'];
	}
	//获取最近50家店
	if($_RQ['lat'] || $_RQ['lng']){
		$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
		$this->session('lat_lng',$lat_lng);
	}
	$lat_lng=$this->session('lat_lng');
	$pindex = max(1, 1);
	$orderbykey='paixu';
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,10000),//获取所有
		'fields'=>array('id','paixu','tuijie','saletype','star','title','image','lat_lng','address','desc','location','mobile'),
		'key'=>'id',
		'orderby'=>$orderby,
		'orderbykey'=>$orderbykey,
	);
	$list=$this->model('model')->gethotel($parameter,$_RQ['limit'],$lat_lng,intval($_RQ['page']),intval($_RQ['juli']));
	foreach($list as &$v){
		$rooms=pdo_getall('jy_jd_room',array('hotelid'=>$v['id']),'','','price asc');
		$rooms['0']['taocan']=json_decode($rooms['0']['taocan'],true);
		$taocan=$this->model('model')->get_uptaocan($rooms['0']);
		if(is_array($taocan)){
			paixu($taocan,'price');
		}
		$oldsaletype=str_array($v['saletype']);
		$saletype=array();
		foreach($oldsaletype as $sv){
			if($this->saletypes[$sv]){
				$saletype[]=array('id'=>$sv,'title'=>$this->saletypes[$sv]);
			}
		}
		$v['saletype']=$saletype;
		$v['price']=$taocan[0]['price']?:$rooms[0]['price'];
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getgoods'){
	//获取最近50家店
	if($_RQ['lat'] || $_RQ['lng']){
		$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
		$this->session('lat_lng',$lat_lng);
	}
	$lat_lng=$this->session('lat_lng');
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
	);
	$pindex = max(1, 1);
	$orderbykey='paixu';
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,10000),//获取所有
		'fields'=>array('id','title','lat_lng','image'),
		'key'=>'id',
		'orderby'=>$orderby,
	);
	$list=$this->model('model')->gethotel($parameter,16,$lat_lng,intval($_RQ['page']));
	foreach($list as &$item){
		$room=pdo_get('jy_jd_room',array('hotelid'=>$item['id']));
		$taocan=json_decode($room['taocan'],true);
		//$room['price']=$this->model('model')->get_minprice($taocan);
		$item=array_merge($item,$room);
	}
	$return['list']=array_values($list);
	exi($return);
}
if($_RQ['op']=='getprovince'){
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	exi($return);
}
if($_RQ['op']=='uppcd'){
	$post=get_postdata();
	if($post['lat'] || $post['lng']){
		$lat_lng=array('lat'=>$post['lat'],'lng'=>$post['lng']);
		$this->session('lat_lng',$lat_lng);
	}
	$this->session('pcd',$post);
	//print_r($this->session('pcd'));exit;
	exi('更新成功！');
}
if($_RQ['op']=='upsettime'){
	$post=get_postdata();
	$this->session('settime',$post);
	exi('更新成功！');
}